package com.github.megatronking.svg.sample.extend;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.github.megatronking.svg.sample.R;
import com.github.megatronking.svg.sample.drawables.dong_feng_ri_chan;
import com.github.megatronking.svg.sample.utils.DimenUtils;
import com.github.megatronking.svg.support.SVGDrawable;
import com.github.megatronking.svg.support.extend.SVGImageView;

public class SVGImageViewSizeSampleActivity extends AppCompatActivity {

    private ImageView mExImageIv;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_extend_imageview_size_sample);
        setTitle(getIntent().getStringExtra("title"));

        // set in code
//        SVGImageView view = (SVGImageView) findViewById(R.id.extend_imageview);
//        view.setSvgSize(DimenUtils.dip2px(this, 24), DimenUtils.dip2px(this, 96));
        mExImageIv = (ImageView) findViewById(R.id.extend_imageview);
        //loadImg();
    }

    private void loadImg(){
        new Thread(){
            @Override
            public void run() {
                super.run();
                SVGDrawable drawable = new SVGDrawable(new dong_feng_ri_chan(SVGImageViewSizeSampleActivity.this));
                MyHandler handler = new MyHandler();
                Message msg = handler.obtainMessage();
                msg.obj = drawable;
                msg.what = 1;
                msg.sendToTarget();
            }
        }.start();

    }

     class MyHandler extends Handler{
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            mExImageIv.setImageDrawable((Drawable) msg.obj);
        }
    }
}
